package com.sxm.yiwei.tools;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;

import com.amap.api.maps.AMap;
import com.amap.api.navi.AMapNaviView;
import com.amap.api.navi.AMapNaviViewListener;
import com.amap.api.navi.enums.NaviType;
import com.amap.api.navi.model.NaviLatLng;
import com.amap.api.services.route.RouteSearch;
import com.sxm.yiwei.MainActivity;
import com.sxm.yiwei.R;
import com.sxm.yiwei.activitis.AppManager;

/**
 * amap
 */
public class YiViMapActivity extends MapBaseActivity implements AMapNaviViewListener,View.OnClickListener{

    private double mEndLatitude;
    private double mEndLongitude;
    private double mStartLatitude;
    private double mStartLongitude;
    private NaviLatLng mEndLatlng;
    private NaviLatLng mStartLatlng;
    private ImageView amapback;
    private ImageView backmain;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Intent intent = getIntent();
        mEndLatitude = intent.getDoubleExtra("mEndLatitude",30.76801+0.01);
        mEndLongitude = intent.getDoubleExtra("mEndLongitude",103.986022+0.01);
        mStartLatitude = intent.getDoubleExtra("mStartLatitude",30.76801+1);
        mStartLongitude = intent.getDoubleExtra("mStartLongitude",103.986022+1);
        mEndLatlng = new NaviLatLng(mEndLatitude,mEndLongitude);
        mStartLatlng = new NaviLatLng(mStartLatitude,mStartLongitude);
        sList.add(mStartLatlng);
        eList.add(mEndLatlng);
        setContentView(R.layout.activity_yi_vi_map);
        amapback = (ImageView) findViewById(R.id.bookcontent_mapback);
        backmain = (ImageView) findViewById(R.id.map_backmain);
        amapback.setOnClickListener(this);
        backmain.setOnClickListener(this);
        mAMapNaviView = (AMapNaviView) findViewById(R.id.map_navi);
        mAMapNaviView.onCreate(savedInstanceState);
        mAMapNaviView.setAMapNaviViewListener(this);
        AMap map = mAMapNaviView.getMap();
        map.clear();
    }
    @Override
    public void onInitNaviSuccess() {
        super.onInitNaviSuccess();
        int strategy = 0;
        try {
            //再次强调，最后一个参数为true时代表多路径，否则代表单路径
            strategy = mAMapNavi.strategyConvert(true, false, false, false, false);
        } catch (Exception e) {
            e.printStackTrace();
        }
        //mAMapNavi.setCarNumber("川", "ZZ1234");
        mAMapNavi.setDetectedMode(RouteSearch.DrivingShortDistance);
        mAMapNavi.calculateDriveRoute(sList, eList, mWayPointList, strategy);
    }

    @Override
    public void onCalculateRouteSuccess() {
        super.onCalculateRouteSuccess();
        mAMapNavi.startNavi(NaviType.GPS);   //实时导航

    }

    @Override
    public void onNaviSetting() {
    }

    @Override
    public void onNaviCancel() {
        finish();
    }

    @Override
    public boolean onNaviBackClick() {

        return false;
    }

    @Override
    public void onNaviMapMode(int i) {

    }

    @Override
    public void onNaviTurnClick() {

    }

    @Override
    public void onNextRoadClick() {

    }

    @Override
    public void onScanViewButtonClick() {

    }

    @Override
    public void onLockMap(boolean b) {

    }

    @Override

    public void onNaviViewLoaded() {

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.bookcontent_mapback:
                finish();
                break;
            case R.id.map_backmain:
                startActivity(new Intent(YiViMapActivity.this, MainActivity.class));
                AppManager.getAppManager().finishAllActivity();
                break;
        }
    }
}
